#ifndef __SERVER_H_
#define __SERVER_H_

#include<stdio.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<string.h>
#include<stdlib.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<pthread.h>
#include<unistd.h>
#include<string.h>
#include<sqlite3.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<json/json.h>
#include<signal.h>
#include<syslog.h>
#define UID_LENTGTH 11
#define PWD_LENGTH  128
#define MSG_LENGTH  256

enum {
    SIGNUP = 0,
    LOGIN,
    BK_LOGIN,
    
};

typedef struct {
    int fd;
    unsigned long cmd;
    char uid[UID_LENTGTH];
    char passwd[PWD_LENGTH];
    char msg[MSG_LENGTH];
} INFO;

struct msg{
    int status;
    char message[70];
};

struct user{
    char uid[50];
    char passwd[50];
    int fd;  //用于保存用户的fd号
};
struct fd{
    int fd; //发送端fd;
    int b_fd; //接收端fd;
};
struct bro{
    char uid[50];   //存放用户好友的uid;
    int status; //状态 0代表在线，1代表不在线
};
struct sql{
    char sql_name[60];
    char tab_name[60];
};

void info_To_Json (INFO *info, char *buf);
void json_To_Info(char *buf, INFO *info);
int add_t(void *arg);
int my_id(void*xx,int yy,char**data,char**name);
int friend_uid(void*xx,int yy,char**data,char**name);
int user_exist(void*xx,int yy,char**data,char**name);
void defend_pro(void);  //创建守护进程
int compare_info(void *info, int column, char **data, char **name);
int compare_uid(void *info, int column, char **data, char **name);
int log_in(INFO *arg);
int sign_in(INFO *arg);
int get_uid(void *info, int column, char **data, char **name);
int log_out(void *arg);
void info_recv(int fd, void *buf);
void json_user(char *p, void *info);
void info_json(void *info, char *buf);
void sig_send(int fd, char *sig);
int talk_to(void *arg);
int get_brolist(void *arg);
int add_bro(void *arg);
int del_bro(void *arg);
int agree_add(void *arg);
void *sys_msg(void *arg);
void end_sig(int arg);
void msg_json(void *info, char *buf);
int get_msg(void *info, int column, char **data, char **name);
//int bro_uid(void *info, int column, char **data, char **name);

#endif
